// JavaScript Document

var currentDATE = 1;
var currentRPI = 1;
var currentTROY = 1; 
var DATElist = "";
var RPIevents = "";
var TROYevents = "";

$(document).ready(function(){			

  $("#RPI-previous").click(showPreviousRPI);
  $("#RPI-next").click(showNextRPI);
  $("#Troy-previous").click(showPreviousTROY);
  $("#Troy-next").click(showNextTROY);
  $("#Date-previous").click(showPreviousDATE);
  $("#Date-next").click(showNextDATE);  
  
  //--------------------------------------------------
  //I'm pretty sure this code can be condensed into two
  //functions since for every "Event" scroller the same
  //action is performed. 
  
  var RPIwidth = 0;
  RPIevents = $(".RPI-event");
  RPIevents.each(function(i){
    RPIwidth += this.clientWidth;
  });
  $("#RPI-box").width(RPIwidth);
  $("#RPI-scroller").attr({scrollLeft: 0});
  
  var TROYwidth = 0;
  TROYevents = $(".Troy-event");
  TROYevents.each(function(i){
    TROYwidth += this.clientWidth;
  });
  $("#Troy-box").width(TROYwidth);
  $("#Troy-scroller").attr({scrollLeft: 0}); 
  
  var DATEwidth = 0;
  DATElist = $(".dates");
  DATElist.each(function(i){
    DATEwidth += this.clientWidth;
  });
  $("#Date-box").width(DATEwidth);
  $("#Date-scroller").attr({scrollLeft: 0});
  //--------------------------------------------------
});
/* Code I was updating
function calculateWidth(events)
{
	var tempWidth = this.clientWidth;
	
}
*/
function showPreviousRPI()
{
  currentRPI--;
  scrollRPIbar();
}

function showNextRPI()
{
  currentRPI++;
  scrollRPIbar();
}

function scrollRPIbar()
{
  var scrollAmount = 0;
  RPIevents.each(function(i){
    if(currentRPI - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#RPI-scroller").animate({scrollLeft: scrollAmount}, 1000);
}


function showPreviousTROY()
{
  currentTROY--;
  scrollTROYbar();
}

function showNextTROY()
{
  currentTROY++;
  scrollTROYbar();
}

function scrollTROYbar()
{
  var scrollAmount = 0;
  TROYevents.each(function(i){
    if(currentTROY - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#Troy-scroller").animate({scrollLeft: scrollAmount}, 1000);
}


function showPreviousDATE()
{
  currentDATE--;
  scrollDATEbar();
}

function showNextDATE()
{
  currentDATE++;
  scrollDATEbar();
}

function scrollDATEbar()
{
  var scrollAmount = 0;
  DATElist.each(function(i){
    if(currentDATE - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#Date-scroller").animate({scrollLeft: scrollAmount}, 1000);
}
